const config = {
  // 根据环境变量决定使用哪个background script
  background: {
    entry: process.env.PLASMO_MANIFEST_VERSION === "mv2" 
      ? "./src/background-v2.ts" 
      : "./src/background.ts"
  },
  
  // 根据manifest版本设置不同的输出目录
  outDir: process.env.PLASMO_MANIFEST_VERSION === "mv2" 
    ? "./build-v2" 
    : "./build",
  
  // V2特定的manifest转换逻辑（结构转换，具体配置从package.json读取）
  manifest: (manifest: any, { manifestVersion }: { manifestVersion: "mv2" | "mv3" }) => {
    if (manifestVersion === "mv2") {
      // 移除V3特有的字段
      delete manifest.host_permissions;
      delete manifest.action;
      
      // V2使用browser_action而不是action
      if (manifest.action) {
        manifest.browser_action = manifest.action;
        delete manifest.action;
      }
    }
    
    return manifest;
  }
}

export default config